This file contains the instructions for using ITK toolkit for the affine and deformable image registration. It assumes that the images are roughly pre-aligned using rigid transformation.

1. Install ITK 
You can find the instructions in the ItkSoftwareGuide (http://www.itk.org/ItkSoftwareGuide.pdf)

I also provide the installation that worked for us with all necessary packages already installed. I used version 3.20 of ITK. Versions starting from 4.0 are different but the registration scripts work as well. The installation and compilation of the files is slightly different for ITK 4.0.

a) Download ITK version 3.20 (from http://www.itk.org/) to <source> folder
b) Create <bin> folder
c) Open command line and go to the <bin> folder:
	cd <bin>
d) print:
	cmake <source>
e) print:
	make


2. Compile affine and deformable registration scripts

a) Create <scripts> folder
b) Copy all supplementary scripts into the <scripts> folder
c) Open command line
d) Define ITK_DIR variable:
	export ITK_DIR=<bin>/lib/InsightToolkit/
e) print:
	cmake .
d) print:
	make


3. Run registration. 
You can use the file register.sh that runs all the scripts in the correct order:
- AffineRegistration defines affine transform for registration using reference channel
- DeformableRegistration defines deformable transform for registration using reference channel
- ApplyAffineTransform applies affine transform to the gene expression channel
- ApplyDeformableTransform applies deformable transform to the affined gene expression channel

To run the script you need to provide the following parameters:
- fixedFileName is a name of the file containing template (8 bit image with the reference channel only)
- movingFileName is a name of the file containing a sample image that will be registered to the template (8 bit image with the reference channel only)
- geneFileName is the name of the file containing the gene expression channel of a sample image (8 bit image containing gene expression signal only)
- outputFileMask is mask for the output file

The register scripts generates 7 output files:
Affine step:
- <outputFileMask>_mr_aff20_transform.txt contains affine transform parameters
- <outputFileMask>_mr_aff20.tiff contains moving image after affine transformation
- <outputFileMask>_dr7sam_before.tiff contains overlaid fixed and moving images after affine registration
- <outputFileMask>_ir20sam_red.tiff contains gene expression channel of the moving image after affine transformation

Deformable step:
- <outputFileMask>_dr7sam_field.mha contains deformable transform parameters
- <outputFileMask>_dr7sam.tiff contains sample image after deformable trasnformation
- <outputFileMask>_dr7sam_after.tiff contains overlaid fixed and moving images after deformable registration
- <outputFileMask>_dr7sopt_red.tiff contains gene expression channel of the sample image after affine transformation. This is a final registered gene expression channel
